package listbyorder.access101_200.test108;

import listbyorder.utils.TreeNode;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/7 10:29
 */
public class Solution1 {

    // 将有序数组转换为二叉搜索树
    public TreeNode sortedArrayToBST(int[] nums) {
        return helper(nums, 0, nums.length);
    }

    private TreeNode helper(int[] nums, int l, int r) {
        if (l >= r) return null;
        int mid = (l + r) >> 1;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = helper(nums, l, mid);
        root.right = helper(nums, mid + 1, r);
        return root;
    }
}
